package com.example.access_control.Controller;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.example.access_control.AccessControl.AccessControlInit;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

@Slf4j
@RestController
@RequestMapping("/hk/user")
public class userController {

    @Autowired
    public AccessControlInit accessControlInit;


    /**
     * 插入用户
     */
    @PostMapping("/insert/user")
    @ResponseBody
    public String insertUser(@RequestBody JSONObject data) throws Exception {
        if (StrUtil.isEmpty(data.getStr("accessControlId"))) {
            return "fill";
        }
        log.info("[Module]插入用户");

        String statusString = accessControlInit.insertUser(data);
        return statusString;
    }

    /**
     * 删除用户
     */
    @PostMapping("/delete/user")
    @ResponseBody
    public String deleteUser(@RequestBody JSONObject data) throws Exception {
        if (StrUtil.isEmpty(data.getStr("accessControlId"))) {
            return "fill";
        }
        log.info("[Module]删除用户");
        String statusString = accessControlInit.deleteUser(data);
        return statusString;
    }


    /**
     * 用户下发人脸图片
     */
    @PostMapping("/send/face")
    @ResponseBody
    public String sendFace(@RequestBody JSONObject data) throws Exception {
        if (StrUtil.isEmpty(data.getStr("accessControlId"))) {
            return "fill";
        }
        log.info("[Module]下发人脸图片");
        accessControlInit.sendFace(data);
        return "success";
    }
}
